package cn.tedu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Demo10 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String username = sc.nextLine();
        System.out.println("请输入密码:");
        String password = sc.nextLine();
        try (Connection conn = DBUtils.getConn()){
            Statement s = conn.createStatement();
            ResultSet rs = s.executeQuery("select  username ,password from user ");
            //循环遍历查找不可取;
            while (rs.next()){
                String name = rs.getString(1);
                String pw = rs.getString(2);
                if (username.equals(name)){
                    if (password.equals(pw)){
                        System.out.println("登录成功!");
                        return;
                    }else{
                        System.out.println("用户名或密码错误!");
                        return;
                    }
                }
            }
            System.out.println("用户名错误!");
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
